import Vue from 'vue'
import VueRouter from 'vue-router'
import DogManagement from '@/views/DogManagement.vue'
import DogAdd from '@/views/DogAdd.vue'
import DogEdit from '@/views/DogEdit.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/dogs'
  },
  {
    path: '/dogs',
    name: 'DogManagement',
    component: DogManagement,
    meta: {
      title: '狗狗品种管理'
    }
  },
  {
    path: '/dogs/add',
    name: 'DogAdd',
    component: DogAdd,
    meta: {
      title: '添加新品种'
    }
  },
  {
    path: '/dogs/edit/:id',
    name: 'DogEdit',
    component: DogEdit,
    meta: {
      title: '编辑品种信息'
    }
  },
  {
    path: '/dogs/:id',
    name: 'DogDetail',
    component: () => import('@/views/DogDetailPage.vue'),
    meta: {
      title: '狗狗详情'
    }
  },
  {
    path: '/scene-config',
    name: 'SceneConfig',
    component: () => import('@/views/SceneConfigPage.vue'),
    meta: {
      title: '场景配置'
    }
  },
  {
    path: '/pet-reaction-configs',
    name: 'PetReactionConfig',
    component: () => import('@/views/PetReactionConfigPage.vue'),
    meta: {
      title: '宠物反应配置'
    }
  },
  {
    path: '/items-and-rewards',
    name: 'ItemsAndRewards',
    component: () => import('@/views/ItemsAndRewards.vue'),
    meta: {
      title: '物品与奖励管理'
    }
  },
  {
    path: '/mood-config',
    name: 'MoodConfig',
    component: () => import('@/views/MoodConfigPage.vue'),
    meta: {
      title: '心情配置'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
